﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ueEngine.Framework.Empires
{
    class PageBuilderRegexpLib
    {
        //匹配空链
        private const string emptylinkcheck = "(?<=\\s)((src)|(href))\\s?=\\s?['\"]{2}(?=\\s|>)";
        public static string EmptyLinkCheck { get { return emptylinkcheck; } }

        //匹配编码方式
        private const string encodingcheck = "(?<=meta.*charset=).*?(?=(;text/html)?\")";
        public static string EncodingCheck { get { return encodingcheck; } }

        //匹配head段
        private const string headpicker = "(?<=<head>).*?(?=</head>)";
        public static string HeadPicker { get { return headpicker; } }

        //匹配head段
        private const string titlepicker = "<title>.*?</title>";
        public static string TitlePicker { get { return titlepicker; } }

        //匹配keyword
        private const string keywordspicker = "<meta.*?name=\"?keywords\"?.*?/>";
        public static string Keywordspicker { get { return keywordspicker; } }

        //匹配body段
        private const string bodypicker = "(?<=<body>).*?(?=</body>)";
        public static string BodyPicker { get { return bodypicker; } }

        //匹配src=".."部分
        private const string srcpicker = "(?<=src=\").*?(?=\")";
        public static string SrcPicker { get { return srcpicker; } }

        //匹配href=".."部分
        private const string hrefpicker = "(?<=<link.*?href=\").*?(?=\")";
        public static string HrefPicker { get { return hrefpicker; } }

        //匹配a href="..."部分
        private const string ahrefpicker = "(?<=<a.*?href=\")[\\./\\a-zA-Z0-9]+\\.html?.*?(?=\")";
        public static string AHrefPicker { get { return ahrefpicker; } }

        //匹配jquery修改通过attr 修改src 或href
        private const string jqueryattrpicker = "(?<=\\$.*?attr\\()[\"']\\w+[\"'],.*?(?=\\))";
        public static string JqueryAttrPicker { get { return jqueryattrpicker; } }

        //匹配empires标签
        private const string labelpick = "<empires.*?</empires>";
        public static string LabelPick { get { return labelpick; } }

        //匹配fill标签内部字段
        private const string fillinnertext = "(?<=<fill.*?>).*?(?=</fill>)";
        public static string FillInnerText { get { return fillinnertext; } }

        /// <summary>
        /// 匹配empires标签
        /// </summary>
        private const string empirestext = "</?empires.*?>";
        public static string EmpiresText { get { return empirestext; } }

        //匹配fill标签
        private const string filltext = "<fill.*?>.*?</fill>";
        public static string FillText { get { return filltext; } }

        private const string filedpick = "{:.+?}";
        /// <summary>
        /// 匹配填充字段如{:Date}
        /// </summary>
        public static string FiledPick { get { return filedpick; } }

        /// <summary>
        /// 捕捉empires标签的name属性
        /// </summary>
        private const string empiresLabel = "<empires\\s+name=\"(?<name>\\w+)\".*?>";
        public static string EmpiresLabel { get { return empiresLabel; } }

        /// <summary>
        /// 捕获empires name="system"的method值
        /// </summary>
        private const string sysMethodLabel = "(?<=<method\\s+name=\")\\w+(?=\"\\s*/>)";
        public static string SysMethodLabel { get { return sysMethodLabel; } }

        /// <summary>
        /// 捕获ignore标签
        /// </summary>
        private const string ignoreLabel = "<ignore>.*?</ignore>";
        public static string IgnoreLabel { get { return ignoreLabel; } }

        /// <summary>
        /// 匹配empires标签内部字段
        /// </summary>
        private const string empiresInnerText = "(?<=<empires.*?>).*?(?=</empires>)";
        public static string EmpiresInnerText { get { return empiresInnerText; } }

        /// <summary>
        /// 匹配text或fill标签
        /// </summary>
        private const string textOrFillLabel = "<(?<lb>\\w+).*?>.*?</\\k<lb>>";
        public static string TextOrFillLabel { get { return textOrFillLabel; } }

        /// <summary>
        /// 模式抓取
        /// </summary>             
        private const string modecatch = "{:(?<field>\\w+)/?(i:(?<idx>\\d{1,3}))?/?(s:(?<sub>\\d{1,3}\\,\\d{1,3}))?/?(d:(?<def>.*?))?}";
        public static string ModeCatch { get { return modecatch; } }

        /// <summary>
        /// 抓取标签
        /// </summary>
        private const string labelcatch = "<(?<label>\\w+)\\s?(mode=\"(?<mode>\\w+)\")?\\s?(item=\"(?<item>\\d+)\")?>.*?</\\k<label>>";
        public static string LabelCatch { get { return labelcatch; } }

        /// <summary>
        /// 抓取lab中内容
        /// </summary>
        private const string labelInner = "(?<=<(?<ln>\\w+)\\s?.*?>)(?<text>.*?)(?=</\\k<ln>>)";
        public static string LabelInner { get { return labelInner; } }

        /// <summary>
        /// 匹配where标签，expression分组为判断条件 left分组为左表达式 sign分组为符合 right分组为右表达式 content分组为内容 
        /// </summary>
        private const string whereLabel = "<where\\s+option=\"(?<expression>(?<left>.*?)(?<sign>[><=]{1,2})(?<right>.*?))\">(?<content>.*?)</where>";
        public static string WhereLabel { get { return whereLabel; } }
    }
}
